<template>
  <div>
    <div class="select-box">
      <el-select v-model="currentYear" size="mini" style="width: 120px; margin-right: 10px" @change="change">
        <el-option
          v-for="item in arr"
          :key="item"
          :label="item"
          :value="item"
        />
      </el-select>

      <el-select v-model="currentMonth" size="mini" style="width: 120px; margin-right: 10px" @change="change">
        <el-option
          v-for="item in 12"
          :key="item"
          :label="item"
          :value="item"
          @change="change"
        />
      </el-select>

    </div>
    <el-calendar v-model="current">
      <template #dateCell="{date,data}">
        <div class="date-content">
          <span class="text" :class="{current: data.isSelected}">{{ date.getDate() }}</span>
          <span class="rest">休</span>
        </div>
      </template>
    </el-calendar>
  </div>
</template>

<script>

export default {
  name: 'WorkCalendar',
  data() {
    return {
      currentYear: this.getyear(),
      currentMonth: this.getmonth(),
      current: new Date()
    }
  },
  computed: {
    arr() {
      const timearr = []
      for (let i = this.currentYear - 10; i < this.currentYear + 10; i++) {
        timearr.push(i)
      }
      return timearr
    }
    // showRest(date) {
    //   return date.getMonth() === 5
    // }

  },
  watch: {
    current(value) {
      this.currentYear = value.getFullYear()
      this.currentMonth = +value.getMonth() - 1
    }
  },
  methods: {

    getyear() {
      const time = new Date()
      const year = +time.getFullYear()
      return year
    },
    getmonth() {
      const time = new Date()
      const month = +time.getMonth()
      return month
    },
    // 选择框改变,日历组件跟着改变
    change() {
      this.current = new Date(this.currentYear, this.currentMonth - 1)
    }

  }
}
</script>

<style lang="scss" scoped>
.select-box {
  display: flex;
  justify-content: flex-end;
}

::v-deep .el-calendar__header {
   display: none;
 }

::v-deep .el-calendar-day {
  height:  auto;
 }
.date-content {
  height: 40px;
  text-align: center;
  line-height: 40px;
  font-size: 14px;
}
.date-content .rest {
  color: #fff;
  border-radius: 50%;
  background: rgb(250, 124, 77);
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;
  font-size: 12px;
  margin-left: 10px;
}
.date-content .text{
  width: 20px;
  height: 20px;
  line-height: 20px;
 display: inline-block;

}
.current{
   background: #409eff;
   color: #fff;
   border-radius: 50%;
 }
</style>
